package com.demo.shardingsphere5.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.shardingsphere5.dao.domain.User;
import com.demo.shardingsphere5.dao.mapper.UserMapper;
import com.demo.shardingsphere5.service.UserService;
import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 解析sql中指定字段的值取模分片到特定db
 * ShardingSphere5提供行表达式分片类：{@link InlineShardingAlgorithm}
*/
@Service
public class HintInLineUserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService {

    public void insert(Long userId) {
        User user = new User();
        user.setUserName("aaa");
        user.setUserId(userId);

        super.save(user);
    }

    public List<User> queryByUserId(Long userId) {
        return super.lambdaQuery().eq(User::getUserId, userId).list();
    }
}




